The TTTTccccllll____CCCCrrrreeeeaaaatttteeeeIIIInnnntttteeeerrrrpppp procedure returns a pointer to a Tcl_Interp
structure. This pointer is then passed into other Tcl procedures to
process commands in the interpreter and perform other operations on the
interpreter. Interpreter structures contain many many fields that are
used by Tcl, but only three that may be accessed by clients: _r_e_s_u_l_t,
_f_r_e_e_P_r_o_c, and _e_r_r_o_r_L_i_n_e.
The _r_e_s_u_l_t and _f_r_e_e_P_r_o_c fields are used to return results or error
messages from commands. This information is returned by command
procedures back to TTTTccccllll____EEEEvvvvaaaallll, and by TTTTccccllll____EEEEvvvvaaaallll back to its callers. The
_r_e_s_u_l_t field points to the string that represents the result or error
message, and the _f_r_e_e_P_r_o_c field tells how to dispose of the storage for
the string when it isn't needed anymore. The easiest way for command
procedures to manipulate these fields is to call procedures like
TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt or TTTTccccllll____AAAAppppppppeeeennnnddddRRRReeeessssuuuulllltttt; they will hide all the details of
managing the fields. The description below is for those procedures that
manipulate the fields directly.
Whenever a command procedure returns, it must ensure that the _r_e_s_u_l_t
field of its interpreter points to the string being returned by the
command. The _r_e_s_u_l_t field must always point to a valid string. If a
command wishes to return no result then _i_n_t_e_r_p->_r_e_s_u_l_t should point to an
empty string. Normally, results are assumed to be statically allocated,
which means that the contents will not change before the next time
TTTTccccllll____EEEEvvvvaaaallll is called or some other command procedure is invoked. In this
case, the _f_r_e_e_P_r_o_c field must be zero. Alternatively, a command
procedure may dynamically allocate its return value (e.g. using mmmmaaaalllllllloooocccc)
and store a pointer to it in _i_n_t_e_r_p->_r_e_s_u_l_t. In this case, the command
procedure must also set _i_n_t_e_r_p->_f_r_e_e_P_r_o_c to the address of a procedure
that can free the value (usually ffffrrrreeeeeeee). If _i_n_t_e_r_p->_f_r_e_e_P_r_o_c is non-zero,
then Tcl will call _f_r_e_e_P_r_o_c to free the space pointed to by _i_n_t_e_r_p-
>_r_e_s_u_l_t before it invokes the next command. If a client procedure
overwrites _i_n_t_e_r_p->_r_e_s_u_l_t when _i_n_t_e_r_p->_f_r_e_e_P_r_o_c is non-zero, then it is
responsible for calling _f_r_e_e_P_r_o_c to free the old _i_n_t_e_r_p->_r_e_s_u_l_t (the
TTTTccccllll____FFFFrrrreeeeeeeeRRRReeeessssuuuulllltttt macro should be used for this purpose).